app.controller('RtLocationModalCtrl', function($scope, $modalInstance, param, ajax) {

    $scope.submitting = false;
    $scope.param = param;
    if ($scope.param.data == null) {
        $scope.param.data = {};
    }
    $scope.param.data.address = $scope.param.ad;
    $scope.param.data.addressMore = $scope.param.addressMore;

    //获取城市列表
    (function() {
        ajax.call(new Req.GET({
            resource: 'city/rt/list'
        })).then(function(result) {
            $scope.citylist = result.result;
            var address = $scope.param.address;
            var strs = address.split("市");
            for (var i = 0; i < $scope.citylist.length; i++) {
                if ($scope.citylist[i].name == strs[0]) {
                    $scope.citylist.selected = $scope.citylist[i];
                    break;
                }
            }
        }, function() { });
    })();

    $scope.ok = function() {
        if ($scope.myForm.$valid) {
            $scope.param.data.point = $scope.param.point;
            $scope.param.data.cityId = $scope.citylist.selected.id;
            $scope.param.data.city = $scope.citylist.selected.name;
            $scope.param.data.recommend = true;
            $modalInstance.close($scope.param);
        }
    };

    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
        $scope.submitting = false;
    };
});